package com.tbi.graphcolouring;

import java.io.IOException;
import java.util.List;

import com.tbi.graphcolouring.appframe.UIModel;
import com.tbi.graphcolouring.io.ColParser;
import com.tbi.graphcolouring.io.FileReader;

public class GraphFactory {
	
	public static BaseGraph load(String path){
		BaseGraph loadedGraph = null;
		try {
			List<String> fileContent = FileReader.read(path);
			ColParser parser = new ColParser(fileContent);
			
			loadedGraph = new BaseGraph(parser.getGraphSize());
			
			for(Edge v : parser.getVertices()){
				loadedGraph.addConnection(v.from, v.to);
			}
			
			UIModel.model.put("nodes_number", parser.getGraphSize()+"");
			UIModel.model.put("edges_number", parser.getEdgesNumber()+"");
			UIModel.model.put("filename", path.substring(path.lastIndexOf("\\")+1, path.length()));
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return loadedGraph;
	}
}
